namespace UniversalAdminSystem.Application.Common.Results;

/// <summary>
/// 统一响应结果基类
/// </summary>
public class Result
{
    public bool IsSuccess { get; }
    public string Message { get; }
    public string[] Errors { get; }

    protected Result(bool isSuccess, string message, string[]? errors = null)
    {
        IsSuccess = isSuccess;
        Message = message;
        Errors = errors ?? Array.Empty<string>();
    }

    public static Result Success(string message = "操作成功")
    {
        return new Result(true, message);
    }

    public static Result Failure(string message, string[]? errors = null)
    {
        return new Result(false, message, errors);
    }
}

/// <summary>
/// 带数据的响应结果
/// </summary>
public class Result<T> : Result
{
    public T? Data { get; }

    protected Result(bool isSuccess, string message, T? data, string[]? errors = null)
        : base(isSuccess, message, errors)
    {
        Data = data;
    }

    public static Result<T> Success(T data, string message = "操作成功")
    {
        return new Result<T>(true, message, data);
    }

    public static new Result<T> Failure(string message, string[]? errors = null)
    {
        return new Result<T>(false, message, default, errors);
    }

    public static implicit operator Result<T>(T data) => Success(data);
} 